package array;

/**
 * 乘水最多的容器 https://leetcode.cn/problems/container-with-most-water/
 *
 * 对撞双指针，移动高的那一侧结果一定是更小，所以移动矮的那一侧
 */
public class maxArea {
    public static void main(String[] args) {
        int[] height = new int[]{1, 1};
        System.out.println(maxArea(height));
    }

    public static int maxArea(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int max = 0;
        while (left != right) {
            int tempMax = Math.min(height[left], height[right]) * (right - left);
            max = Math.max(tempMax, max);
            if (height[left] <= height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return max;
    }
}
